package com.sairobo.admin.modules.srblive.manager.impl;

import java.util.Arrays;
import java.util.List;

import java.util.HashMap;
import java.util.Map;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.sairobo.base.common.constant.QueryConts;
import com.sairobo.base.common.entity.Page;
import com.sairobo.base.common.entity.Query;
import com.sairobo.admin.modules.srblive.dao.SrbliveNewsMapper;
import com.sairobo.admin.modules.srblive.entity.SrbliveNews;
import com.sairobo.admin.modules.srblive.manager.SrbliveNewsManager;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

/**
 * 客服消息表
 *
 * @author admin
 * @email sairobo
 * @url www.sairobo.com
 * @date 2018年1月11日 下午2:12:02
 */
@Component("srbliveNewsManager")
public class SrbliveNewsManagerImpl extends ServiceImpl<SrbliveNewsMapper,SrbliveNews> implements SrbliveNewsManager {
    
	@Override
	public List<SrbliveNews> listSrbliveNews(Page<SrbliveNews> page, Query search) {
        EntityWrapper<SrbliveNews> ew=new EntityWrapper<SrbliveNews>();
        //搜索条件
        Map map = (HashMap)search.get(QueryConts.SEARCH_KEYWORD);
        String key = (String) map.get("key");
        if(StringUtils.isNotEmpty(key)){
            ew.like("title",key);
        }
        ew.orderBy("id",false);
        return baseMapper.selectPage(page,ew);
	}

	@Override
	public int saveSrbliveNews(SrbliveNews srbliveNews) {
        return baseMapper.insert(srbliveNews);
	}

	@Override
	public SrbliveNews getSrbliveNewsById(Long id) {
        SrbliveNews test = baseMapper.selectById(id);
        return test;
	}

	@Override
	public int updateSrbliveNews(SrbliveNews srbliveNews) {
        return baseMapper.updateById(srbliveNews);
	}

	@Override
	public int batchRemove(Long[] id) {
        int count = baseMapper.deleteBatchIds(Arrays.asList(id));
        return count;
	}
	
}
